// const baseURL = 'http://192.168.28.208:8888'
const baseURL = 'http://8.139.5.28:3000'

const http = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + options.url,
			method: options.method || 'GET',
			header: {
				Authorization: uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
				userType: 'user'
			},
			data: options.data || {},
			success: (res) => {
				const data = res.data
				data.code = data.code + ''
				if (data.code === '401') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				} else if (data.code !== '200') {
					uni.showToast({
						icon: 'error',
						title: '操作失败'
					})
				}
				resolve(data)
			},
			fail: (error) => {
				uni.showToast({
					icon: 'error',
					title: '系统错误'
				})
				reject(error)
			}
		})
	})
}

export default http
